import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:pull_to_refresh_flutter3/pull_to_refresh_flutter3.dart';

class Initialization {
  static Widget initRefreshConfiguration({required Widget child}) {
    return RefreshConfiguration(
      // 下拉刷新初始化
      headerBuilder: () => ClassicHeader(
        // refreshingIcon: Icon(Icons.home),
        textStyle: TextStyle(color: Colors.black),
        failedIcon: Icon(Icons.error, color: Colors.black),
        completeIcon: Icon(Icons.done, color: Colors.black),
        idleIcon: Icon(Icons.arrow_downward, color: Colors.black),
        releaseIcon: Icon(Icons.refresh, color: Colors.black),
        // refreshStyle: RefreshStyle.Follow,

        refreshingIcon: SizedBox(
          width: 25.0,
          height: 25.0,
          child: defaultTargetPlatform == TargetPlatform.iOS
              ? const CupertinoActivityIndicator()
              : const CircularProgressIndicator(
                  strokeWidth: 2.0,
                  color: Colors.black,
                ),
        ),
        outerBuilder: (child) {
          return Container(
            padding: EdgeInsets.only(bottom: 10),
            alignment: Alignment.bottomCenter,
            decoration: BoxDecoration(
                gradient: LinearGradient(
              colors: [Colors.blue.shade100, Colors.blue],
              begin: Alignment.topCenter,
              end: Alignment.bottomCenter,
            )),
            height: 100.0,
            child: child,
          );
        },
      ), // 配置默认头部指示器,假如你每个页面的头部指示器都一样的话,你需要设置这个
      footerBuilder: () => ClassicFooter(
        textStyle: TextStyle(color: Colors.black),
        failedIcon: Icon(Icons.error, color: Colors.black),
        canLoadingIcon: Icon(Icons.autorenew, color: Colors.black),
        idleIcon: Icon(Icons.arrow_upward, color: Colors.black),
        loadStyle: LoadStyle.ShowWhenLoading,
        height: 100,
        outerBuilder: (child) {
          return Container(
            padding: EdgeInsets.only(top: 10, bottom: 40),
            alignment: Alignment.topCenter,
            height: 100.0,
            // color: Colors.red,
            decoration: BoxDecoration(
                gradient: LinearGradient(
              colors: [Colors.blue.shade100, Colors.blue],
              begin: Alignment.bottomCenter,
              end: Alignment.topCenter,
            )),
            child: child,
          );
        },
        loadingIcon: SizedBox(
          width: 25.0,
          height: 25.0,
          child: defaultTargetPlatform == TargetPlatform.iOS
              ? const CupertinoActivityIndicator()
              : const CircularProgressIndicator(
                  strokeWidth: 2.0, color: Colors.black),
        ),
      ), // 配置默认底部指示器
      enableScrollWhenTwoLevel: true,

      headerTriggerDistance: 80.0, // 头部触发刷新的越界距离
      springDescription: SpringDescription(
          stiffness: 170,
          damping: 16,
          mass: 1.9), // 自定义回弹动画,三个属性值意义请查询flutter api
      maxOverScrollExtent: 100, //头部最大可以拖动的范围,如果发生冲出视图范围区域,请设置这个属性
      maxUnderScrollExtent: 0, // 底部最大可以拖动的范围
      enableScrollWhenRefreshCompleted:
          true, //这个属性不兼容PageView和TabBarView,如果你特别需要TabBarView左右滑动,你需要把它设置为true
      enableLoadingWhenFailed: true, //在加载失败的状态下,用户仍然可以通过手势上拉来触发加载更多
      hideFooterWhenNotFull: false, // Viewport不满一屏时,禁用上拉加载更多功能
      enableBallisticLoad: true, // 可以通过惯性滑动触发加载更多
      enableLoadingWhenNoData: true,
      enableRefreshVibrate: false,
      enableLoadMoreVibrate: true,
      shouldFooterFollowWhenNotFull: (state) {
        // If you want load more with noMoreData state ,may be you should return false
        return false;
      },
      child: child,
    );
  }
}
